package com.pda.xinma.presenter;

import com.pda.xinma.bean.HandingInStaticsBean;
import com.pda.xinma.bean.HnadingInDetailListBean;
import com.pda.xinma.contract.HandingInStaticsContract;
import com.pda.xinma.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import io.reactivex.functions.Consumer;

public class HandingInStaticsPresenter extends BasePresenter<HandingInStaticsContract.View> implements HandingInStaticsContract.Presenter {
    @Override
    public void entryStatistics(String entryNo) {
        NetUtils.geApi().entryStatistics(entryNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<HandingInStaticsBean>>() {
                    @Override
                    public void accept(BaseAppEntity<HandingInStaticsBean> handingInStaticsBeanBaseAppEntity) throws Exception {
                        getView().setStatistics(handingInStaticsBeanBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void entryClose(String entryNo) {
        NetUtils.geApi().entryClose(entryNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<HnadingInDetailListBean>>() {
                    @Override
                    public void accept(BaseAppEntity<HnadingInDetailListBean> hnadingInDetailListBeanBaseAppEntity) throws Exception {
                        getView().finishActivity();
                        getView().showMessage(hnadingInDetailListBeanBaseAppEntity.getMessage());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
